package com.ylr.动态定时任务线程池;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author ylr
 * @version 1.0.0
 * @ClassName DynamicScheduledController.java
 * @Description TODO
 * @createTime 2021年12月20日 11:49:00
 */
//@RestController
public class DynamicScheduledController {

    @Autowired
    @Qualifier("scheduleThreadPool")
    private ScheduledExecutorService executorService;


    private static AtomicInteger i = new AtomicInteger(1);

    @GetMapping("/start")
    public String start() {

        executorService.scheduleAtFixedRate(()->{
            try {
                Thread.sleep(1000*10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("hello!");

        },0,10, TimeUnit.SECONDS);
        return "nice";
    }
}
